package com.franklin.java.utils;

import com.franklin.java.action.move.MyGotoTargetAction;
import com.franklin.java.icon.PluginIcons;
import com.franklin.plugins.common.utils.DataCheckUtils;
import com.intellij.notification.*;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
import com.intellij.ui.components.JBLabel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @author Franklin
 * @since 2021/9/16 17:37
 */
public class NotificationUtils {

    private static Notification getNotification(NotificationType notificationType, String content) {
        return NotificationGroupManager.getInstance()
            .getNotificationGroup("Franklin Notification Group")
            .createNotification("Franklin Java Data Helper", content, notificationType, null);
    }

    private static Notification getErrorNotification(String content) {
        return getNotification(NotificationType.ERROR, content);
    }

    public static void notifyError(@Nullable Project project, String content) {
        getErrorNotification(content)
            .notify(project);
    }

    public static void notifyError(@Nullable Project project, String content, PsiElement gotoElement,@Nullable String targetName) {
        Notification notification = getErrorNotification(content);
        String actionName = "see";
        if (DataCheckUtils.isNotEmpty(targetName)){
            actionName = actionName + " " + targetName;
        }
        notification.addAction(new NotificationAction(actionName) {
            @Override
            public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
                if (gotoElement instanceof Navigatable) {
                    ((Navigatable) gotoElement).navigate(true);
                }
            }
        });

        notification
            .notify(project);
    }
}
